home *** CD-ROM | disk | FTP | other *** search
- /* GetDeviceLogicalAddress.c */
- /*
- * GetDeviceLogicalAddress.c
- * Copyright © 1994-95 Apple Computer Inc. All rights reserved.
- *
- */
- /* .___________________________________________________________________________________.
- | This device retrieves the LogicalAddress and length of a PCI device "register" |
- | It is independent of the Framework driver. This function may only be called |
- | from the driver initialization functions. |
- | This may need extension for certain hardware configurations. |
- .___________________________________________________________________________________.
- */
- /*
- * Revised 95.04.07 to use the definitions in PCI.h
- */
- #include "NCRDriverPrivate.h"
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * GetDeviceLogicalAddress
- *
- * Retrieve the assigned-address property from the Name Registry and search it for
- * the specified addressSpaceSelector. This function uses the device base register
- * only: it ignores the I/O vs. Memory space selector. It will need modification if
- * the hardware supports 64-bit addressing or needs to understand address spaces.
- */
- OSErr
- GetDeviceLogicalAddress(
- RegEntryIDPtr regEntryIDPtr, /* Driver's Name Registery ID */
- PCIRegisterNumber deviceRegister, /* Register in address property */
- LogicalAddress *deviceLogicalAddress, /* Gets the logical address */
- ByteCount *deviceAreaLength /* Gets the area size */
- )
- {
- OSErr status;
- short i; /* Vector index */
- short nAddresses; /* Number of vector elements */
- RegPropertyValueSize assignedAddressSize;
- RegPropertyValueSize logicalAddressSize;
- RegPropertyValue *assignedAddressProperty; /* Assigned Address property */
- PCIAssignedAddressPtr pciAssignedAddressPtr; /* Assigned Address element ptr */
- LogicalAddress *logicalAddressVector; /* AAPL,addresses property */
- StringPtr failureMsg;
-
- Trace(GetDeviceLogicalAddress);
- failureMsg = NULL;
- assignedAddressProperty = NULL;
- logicalAddressVector = NULL;
- if (deviceLogicalAddress == NULL || deviceAreaLength == NULL)
- status = paramErr;
- else {
- /*
- * Fetch the assigned address and AAPL,address properties. Allocate memory
- * for each.
- */
- status = GetThisProperty(
- regEntryIDPtr,
- kPCIAssignedAddressProperty,
- &assignedAddressProperty,
- &assignedAddressSize
- );
- CheckStatus(status, "\pNo assigned-addresses property");
- if (status != noErr)
- failureMsg = "\pNo " kPCIAssignedAddressProperty " property";
- }
- if (status == noErr) {
- status = GetThisProperty(
- regEntryIDPtr,
- kAAPLDeviceLogicalAddress,
- (RegPropertyValue *) &logicalAddressVector,
- &logicalAddressSize
- );
- CheckStatus(status, "\pNo AAPL,address property");
- if (status != noErr)
- failureMsg = "\pNo " kAAPLDeviceLogicalAddress " property";
- }
- if (status == noErr) {
- status = paramErr;
- nAddresses = assignedAddressSize / sizeof (PCIAssignedAddress);
- pciAssignedAddressPtr = (PCIAssignedAddressPtr) assignedAddressProperty;
- for (i = 0; i < nAddresses; i++, pciAssignedAddressPtr++) {
- if (GetPCIRegisterNumber(pciAssignedAddressPtr) == deviceRegister) {
- if (pciAssignedAddressPtr->size.hi != 0 /* 64-bit area? */
- || pciAssignedAddressPtr->size.lo == 0) { /* Zero length */
- /*
- * Open Firmware was unable to assign a valid address to this
- * memory area. We must return an error to prevent the driver
- * from starting up. Is there a better error status?
- */
- status = paramErr;
- failureMsg = "\pBad assigned address size";
- LogHex(
- pciAssignedAddressPtr->size.hi,
- "\ppciAssignedAddressPtr->size.hi"
- );
- LogHex(
- pciAssignedAddressPtr->size.lo,
- "\ppciAssignedAddressPtr->size.lo"
- );
- }
- else if (i >= (logicalAddressSize / sizeof (LogicalAddress))) {
- /*
- * The logical address vector is too small -- this is a bug.
- */
- status = paramErr;
- failureMsg = "\pLogical address size < assigned address size";
- }
- else {
- status = noErr;
- *deviceLogicalAddress = logicalAddressVector[i];
- *deviceAreaLength = pciAssignedAddressPtr->size.lo;
- }
- break; /* Exit loop when we find the desired register */
- }
- }
- CheckStatus(status, "\pNo valid address space");
- if (failureMsg == NULL)
- failureMsg = "\pAddress space not found";
- }
- DisposeThisProperty(&assignedAddressProperty);
- DisposeThisProperty(&logicalAddressVector);
- if (status != noErr)
- PublishInitFailureMsg(status, failureMsg);
- return (status);
- }
-
-